<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>亿欧关键词工具</title>
<script src="lib/jquery-2.1.4.min.js"></script>
<link rel="stylesheet" href="lib/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="lib/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="lib/jquery.ztree.exedit-3.5.min.js"></script>
<SCRIPT type="text/javascript">
	var KWArray = {};  //存放关键词
	<!--
	var setting = {
		view: {
			addHoverDom: addHoverDom,
			removeHoverDom: removeHoverDom,
			selectedMulti: false
		},
		edit: {
			enable: false,
			editNameSelectAll: true,

		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: zTreeOnClick
		}
	};

	function zTreeOnClick(event, treeId, treeNode) {
		$("#theme").empty();
		$("#keywords").empty();
		$.ajax({  
			type: "post",  
			url: "findTheme.php",  
			dataType: "json", 
			data:{    
	             id:treeNode.id
	    	},   
			success: function(KW){  
				//console.info(eval(KW));
				var count=0;			
				$.each(KW,function(key,val){	
					KWArray[count]=val.keyWords;				
					if(val.theme!="--无--"){				
						$("<li class='themes' id='"+count+"'><a href='#'>"+val.theme+"</a><aside><a href='javascript:deleteTheme("+val.ID+","+(count++)+")'><img src='lib/img/deleteIcon.png'></a></aside></li>").appendTo("#theme").bind('click', function() {
							$("#keywords").html(KWArray[this.id]);		
						});
					}else{
						$("<li class='themes' id='"+(count++)+"'><a href='#'>"+val.theme+"</a></li>").appendTo("#theme").bind('click', function() {
							$("#keywords").html(KWArray[this.id]);		
						});
					}
					
				});
			}
		});
	};

	function addHoverDom(treeId, treeNode) {
	};
	function removeHoverDom(treeId, treeNode) {
		$("#addBtn_"+treeNode.tId).unbind().remove();
	};
	
	$(document).ready(function(){
		$.ajax({  
			type: "post",  
			url: "findTheme.php",  
			dataType: "json", 
			data:{    
	             id:1
	    	},   
			success: function(KW){  
				//console.info(eval(KW));
				var count=0;			
				$.each(KW,function(key,val){	
					KWArray[count]=val.keyWords;
					if(val.theme!="--无--"){				
						$("<li class='themes' id='"+count+"'><a href='#'>"+val.theme+"</a><aside><a href='javascript:deleteTheme("+val.ID+","+(count++)+")'><img src='lib/img/deleteIcon.png'></a></aside></li>").appendTo("#theme").bind('click', function() {
							$("#keywords").html(KWArray[this.id]);		
						});
					}else{
						$("<li class='themes' id='"+(count++)+"'><a href='#'>"+val.theme+"</a></li>").appendTo("#theme").bind('click', function() {
							$("#keywords").html(KWArray[this.id]);		
						});
					}
					
				});
			},
			error:function(XMLResponse){alert(XMLResponse.responseText)}
		});
		var zNodes=$("#as").val();
		$.fn.zTree.init($("#treeDemo"), setting, eval(zNodes));
		$("#STheme").change(function(){
			$("#theme").empty();
			$("#keywords").empty();
			var theme=$("#STheme").val();
			$.ajax({  
				type: "post",  
				url: "findTheme.php",  
				dataType: "json", 
				data:{    
					 name:theme
				},   
				success: function(KW){  
					//console.info(eval(KW));
					var count=0;			
					$.each(KW,function(key,val){	
						KWArray[count]=val.keyWords;				
						if(val.theme!="--无--"){				
							$("<li class='themes' id='"+count+"'><a href='#'>"+val.theme+"</a><aside><a href='javascript:deleteTheme("+val.ID+","+(count++)+")'><img src='lib/img/deleteIcon.png'></a></aside></li>").appendTo("#theme").bind('click', function() {
								$("#keywords").html(KWArray[this.id]);		
							});
						}else{
							$("<li class='themes' id='"+(count++)+"'><a href='#'>"+val.theme+"</a></li>").appendTo("#theme").bind('click', function() {
								$("#keywords").html(KWArray[this.id]);		
							});
						} 
						
					});
				}
			});
			});
		
	});
	function deleteTheme(id,liId){
		var psw=prompt("删除后将不能恢复，请输入密码","");
		if(psw=="335335"){
			$.ajax({  
				type: "post",  
				url: "deleteTheme.php",  
				dataType: "json", 
				data:{    
					 id:id
				},   
				success: function(msg){ 					
					alert(msg);
					if(msg=="删除成功！")
						$("#"+liId).remove();
				},
				error:function(XMLResponse){alert(XMLResponse.responseText)}
			});
		}else{
			alert("密码不正确！");
		}
	}
	//-->
</SCRIPT>
<style type="text/css">
h2,h3{
	display:inline;
}
a{
	text-decoration:none;
	color:#000;
}
a:hover{
	text-decoration:underline;
}
#leibie{
	margin-top:20px;
}
textarea{
	resize: none;
	width:400px;
	border-radius: 5px;
}
#STheme{
	border-radius: 5px;
	width:400px;
}
header{
	margin-bottom:20px;
	margin-top:10px;
}
header h3{
	margin-right:5px;
	display:inline;
}
#content{
	margin-left:10px;
	font-size:18px;
}
#resultT{
	position: absolute;
	left: 520px;
	top: 75px;
	
}
#resultT ul{
	list-style:none;
	position:relative;
	left:-49px;
	top:-10px;
}
#resultT ul li{
	margin-bottom:3px;
	position-left:5px;
	padding:3px 15px !important;
	width:355px;
}
#resultT ul li:nth-child(even){
	background:#88abda;
}
#resultT section{
	height:180px;
	width:400px;
	background-color:#efefef;
	position:relative;
	top:5px;
	padding-top:5px;
	overflow:auto;
	border-radius: 5px;
	border-collapse: collapse;
	border: thin outset #c2c2c0;
}
#resultK{
	position:absolute;
	left:520px;
	top:350px;
}
#resultK textarea{
	height:180px;
	font-size:18px;
}
#goleft{
	position:absolute;
	left:450px;
	top:180px;
	width:36px;
	height:30px;
}
#gobottom{
	position:absolute;
	left:700px;
	top:300px;
	width:30px;
	height:36px;
	z-index:99;
}
#theme aside{
	display:inline;
	margin-left:20px;
}
</style>
</head>

<body>
<?php
require('inc/MYSQL_Connection.php');
if(mysqli_connect_errno()){
	echo "<span style='color:#F00'> 数据库连接失败！</span>";
}else{
	$db->query("set names utf8");
	$query2="select * from keywordscategory";   //查询分类
	$result2=$db->query($query2);	
	if($result2->num_rows>0){
		$zNodes='[';
		for($i=0;$i<$result2->num_rows;$i++){
			$row=$result2->fetch_assoc();
			$zNodes=$zNodes.'{ id:'.$row['id'].', pId:'.$row['pId'].', name:"'.$row['name'].'"},';
		}
		$zNodes = substr($zNodes,0,strlen($zNodes)-1); 
		$zNodes=$zNodes.']';
	}else
		$zNodes='[{id:1, pId:0, name:"查无数据！"}]';	
	echo "<div style='display:none'><textarea id='as'>".$zNodes."</textarea></div>";
	$result2->free();
	$db->close();	
}		
?>
<div id="content">
<img src="lib/img/toleft.png" id="goleft">
<img src="lib/img/tobottom.png" id="gobottom">
	<header>
        <h3><a href="makeKeyWords.php">关键词入库</a></h3>
        <h3>关键词查询</h3>
        <h3><a href="keywords.php">关键词处理</a></h3>
        <hr>
    </header>	
    <div id="search">
        通过主题搜索：<br>
        <input type="text" id="STheme">
    </div>
    <div id="leibie">
    	通过类别查找：<br>
        <div class="zTreeDemoBackground left">
            <ul id="treeDemo" class="ztree"></ul>
        </div>
    </div>
    
    <div id="resultT">
    	查询结果：<br>
        <section>
            <ul id="theme"></ul>
        </section>
    </div>
    <div id="resultK">
    	关键词：<br>
    	<textarea id="keywords" readonly></textarea>
    </div>
</div>
</body>
</html>